﻿//
// core.hpp
// ~~~~~~~~
//

#ifndef YUTOPP_BASIC_CORE_HPP
#define YUTOPP_BASIC_CORE_HPP

#include "../url_base64.hpp"
#include "key.hpp"

#include <string>
#include <map>

namespace webapp
{
	namespace basic
	{
		class core
		{
		public:
			typedef std::string					binary_type;
			typedef
				std::map<binary_type, binary_type>
			parameter_type;
			typedef basic_key<binary_type>		key_type;

			core() {}

			core( const key_type& user_key )
				: key_( user_key )
			{}

			core( const binary_type& username, const binary_type& password )
			{
				key_.set_username( username );
				key_.set_password( password );
			}

			//
			void set_key( const key_type& k )
			{
				key_ = k;
			}
			const key_type& get_key() const
			{
				return key_;
			}

			//ヘッダの生成
			binary_type make_header(...) const
			{
				const binary_type gen( key_.get_username() + ":" + key_.get_password() );
				return "Basic " + base64::encode( gen.c_str(), gen.size() );
			}

		private:
			key_type key_;
		};

	} // - basic
} // - webapp

#endif /*YUTOPP_BASIC_CORE_HPP*/
